package subject_set.top101;

/**
 * @author haomin
 * @date 2022/11/02 21:40
 **/
public class BM36 {
    public class Solution {
        public boolean IsBalanced_Solution(TreeNode root) {
            if(root == null) return true;
            int l = findDep(root.left);
            int r = findDep(root.right);
            if(Math.abs(l-r) > 1) return false;
            return IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right);
        }
        private int findDep(TreeNode root){
            if(root == null) return 0;
            return 1 + Math.max(findDep(root.left), findDep(root.right));
        }
    }
}